//提供一个构造函数
function Ball(option) {
    //初始化操作
    this._init(option)
}

//设置原型对象
Ball.prototype = {
    //修正构造器属性
    constructor:Ball,
    _init:function (option) {
        option = option || {};
        this.x = option.x || 0;
        this.y = option.y || 0;
        this.r = option.r || 0;
        this.fillColor = option.fillColor || "black";

        //变化的量：
        this.dx = Math.random()*20 - 10;
        this.dy = Math.random()*20 - 10;
        this.dr = Math.random()*2 + 1;//至少变化一次

    },
    render:function (ctx) {
        ctx.save();
        ctx.beginPath();
        ctx.arc(this.x,this.y,this.r,0,2*Math.PI);
        ctx.fillStyle = this.fillColor;
        ctx.fill();
        ctx.restore();
    },
    update:function () {
        this.x += this.dx;
        this.y += this.dy;
        this.r -= this.dr;

        if( this.r <=0){
            ballArray = _.without(ballArray,this);
        }
    }
};

